package com.oocl.customer.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.customersystem.dto.MUser;
import com.oocl.customersystem.service.MUserManager;
import com.oocl.customersystem.service.impl.MUserManagerImpl;
import com.oocl.customersystem.util.RequestUtil;

/**
 * Servlet implementation class ShowAllMerchant
 */
public class ShowAllMerchant extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private MUserManager mManager;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowAllMerchant() {
        super();
        mManager=new MUserManagerImpl();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String uri = "http://ZHA-ITA097-W7:8999/AdminSystem/muser?method=getWhiteList"; // 等待A端的URI
		List<MUser> mList = null;
		try {
			mList = mManager.gMUsers(uri, null);
		} catch (IOException e) {
			response.sendRedirect("error.jsp");
			return;
		}
		if (mList.size() != 0) {
			response.setContentType("application/json; charset=utf-8"); 				
			response.setHeader("Access-Control-Allow-Origin", "*");
			
			response.getWriter().write(RequestUtil.wrapToJson(mList));
		}
	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
